package de.hochschuletrier.bachelor.antfarm.control.handler;

import javax.swing.JList;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import de.hochschuletrier.bachelor.antfarm.control.ControlFrame;
import de.hochschuletrier.bachelor.antfarm.entity.mes.ActionMessage;
import de.hochschuletrier.bachelor.antfarm.entity.mes.ActionMessageGroup;

public class ActionMessageSelectionHandler implements ListSelectionListener {

	private ControlFrame frame;

	public ActionMessageSelectionHandler(ControlFrame frame) {
		super();
		this.frame = frame;
	}

	@Override
	public void valueChanged(ListSelectionEvent e) {
		@SuppressWarnings("unchecked")
		JList<ActionMessageGroup> list = (JList<ActionMessageGroup>) e
				.getSource();
		ActionMessageGroup g = list.getSelectedValue();
		String t = "";
		for (ActionMessage m : g.getMessages()) {
			t += m.getText() + "\n";
		}
		frame.getTextArea().setText(t);
	}

}
